package com.bobo.Thread;


public class RunnableTest implements Runnable {

	private int pcount=5;
	private Object objlock=new Object();
	 
	@Override
	public void run() {
		//synchronized 线程安全 起到线程互斥的作用，多个线程 只有当获取锁的线程才能对资源进行操作。
		synchronized(objlock){
			while(pcount>0){ 
				pcount--;
				System.out.println(Thread.currentThread().getName()+"卖了一张票，还剩下"+pcount);
		}
		}
			
	}
	
	 
	
	public static void main(String[] args) {
		RunnableTest rtest=new RunnableTest();
		Thread th1=new Thread(rtest,"窗口1");
		Thread th2=new Thread(rtest,"窗口2");
		Thread th3=new Thread(rtest,"窗口3");
		th1.start();
		th2.start();
		th3.start();
	}
}
